<!--
 * @Description: 登录页面
 * @Author: rendc
 * @Date: 2021-09-13 10:58:38
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-14 09:46:49
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>行学天下-登录</title>
  <!-- jQuery -->
  <script src="../../js/jquery.js"></script>
  <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
    integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

  <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
    integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous">
  </script>
</head>

<body>
  <div>
    <div class="input-group">
      <span class="input-group-addon" id="basic-addon1">用户名</span>
      <input id="username" type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
    </div>
    <div class="input-group">
      <span class="input-group-addon" id="basic-addon1">密码</span>
      <input id="password" type="text" class="form-control" placeholder="password" aria-describedby="basic-addon1">
    </div>
    <button type="button" class="btn btn-default">登录</button>
  </div>
</body>
<script>
  function login() {
    var obj = {
      username: $("#username").val(),
      password: $("#password").val()
    }
    // console.log(obj);
    $.ajax({
      url: "http://203.195.246.58:8888/user/login",
      method: "post",
      contentType: "application/json",
      data: JSON.stringify(obj),
      success: function (res) {
        console.log(res);
        sessionStorage.setItem("token", res.data.token)
        $(location).attr("href", "./index.html")
      }
    })
  }
  $("button").click(login);
</script>

</html>